//
//  SEGuideDiagnosisInfoDescCell.swift
//  SmartEyeForPatient
//
//  Created by QDSG on 2021/4/8.
//

import UIKit

class SEGuideDiagnosisInfoDescCell: UITableViewCell {
    
    private var viewModel: SEInquiryInfoViewModel?
    private var endEditing: ((SEInquiryInfoViewModel) -> Void)?

    override func awakeFromNib() {
        super.awakeFromNib()
        backgroundColor = .white
        contentView.backgroundColor = .white
    }
    
    func update(with viewModel: SEInquiryInfoViewModel, endEditing: ((SEInquiryInfoViewModel) -> Void)?) {
        self.viewModel = viewModel
        self.endEditing = endEditing
        textView.text = viewModel.info.illness
    }
    
    @IBOutlet private weak var textView: SETextView! {
        didSet {
            textView.placeholder = "请描述您的症状（既往的健康状况和过去曾经患过的疾病等方面的问题，既往健康状况包括饮食习惯等。）"
            textView.tvDelegate = self
        }
    }
}

// MARK: - SETextViewDelegate

extension SEGuideDiagnosisInfoDescCell: SETextViewDelegate {
    func textViewDidEndEditing(_ textView: UITextView) {
        guard let viewModel = viewModel else { return }
        viewModel.info.illness = textView.text
        endEditing?(viewModel)
    }
}
